<script setup lang="ts">

const route = useRoute()
const { VITE_CASINO_GAME_PAGE_SIZE } = getEnv()

const sortType = ref(EnumCasinoSortType.hot)
const pids = ref('') //供应商
const cid = ref(route.query.cid?.toString() ?? '0')
const ty = ref<string>(route.query?.ty?.toString() ?? '')
const gameTypeReal = ref(route.query.game_type?.toString() ?? '')

// 类别游戏
const paramsCate = computed(() => getTy({
    cid: cid.value,
    sort: sortType.value,
    venue_id: pids.value,
    game_type: cid.value === '100' ? gameTypeReal.value : undefined,
    ty: ty.value,
}))
const {
    page,
    list: cateList,
    total: cateTotal,
    runAsync: runCateGames,
    loading: loadingCate,
    loadMore: loadMoreCate,
} = useList(ApiMemberGameCateGames, {}, { page_size: VITE_CASINO_GAME_PAGE_SIZE })

function onPage(p: number) {
    page.value = p
}
// 检查类别是否开启
function checkCate() {
    return new Promise((resolve, reject) => {
        ApiMemberCateState(getTy({ cid: cid.value || '', ty: route.query.ty as string })).then((res) => {
            if (res === 1) {
                resolve(res)
            }
            else {
                i18nNavigateTo('/')
                reject(res)
            }
        })
            .catch((err) => {
                i18nNavigateTo('/')
                reject(err)
            })
    })
}

function init() {
    // 初始化
    checkCate().then(() => {
        runCateGames(paramsCate.value)
    })
}
init()
</script>
<template>
    <BaseGameList @page="onPage" :loading="loadingCate" :data="cateList" :total="cateTotal" :page="page"
        :page-size="VITE_CASINO_GAME_PAGE_SIZE" />
</template>
<style scoped lang="scss"></style>